﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using YuuzleComic.DALFactory;
using YuuzleComic.DBUtility;

public partial class support_daolian : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            Bitmap bt = this.getDaoLian();
            Response.ContentType = "image/Jpeg";
            Response.Clear();
            bt.Save(Response.OutputStream, ImageFormat.Jpeg);
            bt.Dispose();
            Response.End();
        }
    }

    private Bitmap getDaoLian()
    {
        DataRow dr = DbHelperSQL.Query("select top(1) a.id,a.mhmc,a.mhbm,a.mhfm,b.scount,c.zjmc,e.diqu,f.classname,d.zzmc from comics a join (select COUNT(id) scount,MAX(ordernum) ordernum,cid from zj group by cid) b on a.id=b.cid join zj c on b.ordernum=c.ordernum join zz d on a.zzid=d.id join diqu e on a.dqid=d.id join class f on a.classid=f.id order by hits_d desc").Tables[0].Rows[0];
        Bitmap bt = new Bitmap(480, 360, PixelFormat.Format24bppRgb);
        Graphics g = Graphics.FromImage(bt);
        Font fn = new Font("微软雅黑", 10, FontStyle.Bold);
        g.Clear(Color.White);
        g.DrawString("友情提示", new Font("微软雅黑", 20, FontStyle.Bold), Brushes.Red, new PointF(200, 20));
        g.DrawString("请勿盗链，该漫画来自“雨泽漫画”", new Font("微软雅黑", 10, FontStyle.Bold), Brushes.Red, new PointF(160, 75));
        g.DrawString("在线漫画网官方地址：", new Font("微软雅黑", 12, FontStyle.Bold), Brushes.Gray, new PointF(14, 100));
        g.DrawString("www.yzmanga.com", new Font("微软雅黑", 12, FontStyle.Bold), Brushes.Blue, new PointF(180, 100));
        g.DrawString("今日热门漫画推荐", fn, Brushes.Blue, new PointF(14, 130));
        g.DrawString("漫画：" + dr["mhmc"], fn, Brushes.Black, new PointF(150, 155));
        g.DrawString("别名：" + dr["mhbm"], fn, Brushes.Black, new PointF(150, 175));
        g.DrawString("作者：" + dr["zzmc"], fn, Brushes.Black, new PointF(150, 195));
        g.DrawString("地区：" + dr["diqu"], fn, Brushes.Black, new PointF(150, 215));
        g.DrawString("类型：" + dr["classname"], fn, Brushes.Black, new PointF(150, 235));
        g.DrawString("章数：" + dr["scount"], fn, Brushes.Black, new PointF(150, 255));
        g.DrawString("最新：" + dr["zjmc"], fn, Brushes.Red, new PointF(150, 275));
        g.DrawString("地址：http://www.yzmanga.com/comic/" + dr["id"] + "/", fn, Brushes.Blue, new PointF(150, 295));

        g.DrawString("欢迎到雨泽漫画(www.yzmanga.com)来观看最新、最热的漫画！", fn, Brushes.Gray, new PointF(14, 340));
        //填充图像
        System.Drawing.Image logoimage = System.Drawing.Image.FromFile(Server.MapPath("~/images/logo.gif"));
        System.Drawing.Image newimagebg = System.Drawing.Image.FromFile(Server.MapPath("~/images/cover_bg.gif"));
        //图像定位
        g.DrawImage(logoimage, 14, 14, 180, 60);
        g.DrawImage(newimagebg, 14, 155, 128, 168);
        if (File.Exists(Server.MapPath("~/cpic/" + dr["mhfm"])))
        {
            System.Drawing.Image newimage = System.Drawing.Image.FromFile(Server.MapPath("~/cpic/" + dr["mhfm"]));
            g.DrawImage(newimage, 14, 155, 120, 160);
        }
        //释放图像缓存
        g.Dispose();
        return bt;
    }   
}